import ArcoVue from '@arco-design/web-vue';
import dayjs from 'dayjs';
import NProgress from 'nprogress';
import { createPinia } from 'pinia';
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';
import { createApp } from 'vue';

import App from '@/App.vue';
import { setupDirectives } from '@/directives';
import router from '@/router';
import { useUserStore } from '@/stores';

import '@/assets/styles/index.css';
import '@arco-design/web-vue/dist/arco.css';
import 'nprogress/nprogress.css';

// 创建 Pinia 实例并配置持久化
const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);

const app = createApp(App);

// 安装插件
app.use(pinia);

// 预先初始化用户状态
const userStore = useUserStore();
userStore.initUserData();

app.use(router);
app.use(ArcoVue);

// 注册全局指令
setupDirectives(app);

dayjs.locale('zh-cn');

// 配置 NProgress
NProgress.configure({
  showSpinner: false,
  minimum: 0.2,
  easing: 'ease',
  speed: 500
});

app.mount('#app');
